package com.vtquang.mymaps.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.vtquang.mymaps.MyLocation;
import com.vtquang.mymaps.R;

public class PlaceLocationAdapter extends BaseAdapter {

	private static List<MyLocation> itemDetailsrrayList;
	private LayoutInflater l_Inflater;

	public PlaceLocationAdapter(Context context, List<MyLocation> results) {
		itemDetailsrrayList = results;
		l_Inflater = LayoutInflater.from(context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return itemDetailsrrayList.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return itemDetailsrrayList.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub

		ViewHolde holder;
		if (convertView == null) {
			convertView = l_Inflater
					.inflate(R.layout.places_location_row, null);
			holder = new ViewHolde();
			holder._name = (TextView) convertView.findViewById(R.id.tvName);
			holder._vicinity = (TextView) convertView
					.findViewById(R.id.tvVicinity);
			holder._distance = (TextView)convertView.findViewById(R.id.tvDistance);
			holder._img = (ImageView)convertView.findViewById(R.id.imageView);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolde) convertView.getTag();
		}

		MyLocation loc = itemDetailsrrayList.get(position);
		holder._name.setText(loc.get_name());
		holder._vicinity.setText(loc.get_vicinity());
		holder._distance.setText("Khoảng : " + (int)loc.get_distance() + "m");
		holder._img.setImageDrawable(loc.get_icon());
		
		return convertView;
	}

	private class ViewHolde {
		TextView _name;
		TextView _vicinity;
		TextView _distance;
		ImageView _img;
	}
}
